package com.javaspeak.designpatterns.go4.behavioural.visitor;

/**
 * BigShapeVisitor is responsible for drawing big Shapes.
 * <p>
 * It make senses to centralise the code for drawing Big Shapes.
 * <p>
 * <p>
 * As time goes on we may want to create new Visitors like "ShinyShapeVisitor"
 * or "3DShapeVisitor".
 * <p>
 * Instead of having to go and edit many different shape classes to produce a
 * different version of their shape a new Visitor can be created and the code
 * placed in one centralised place.
 * <p>
 * When we call the "accept( ShapeVisitor shapeVisitor )" method on a
 * TriangleVisitable or SquareVisitable we pass it an implementation of
 * ShapeVisitor such as this BigShapeVisitor.
 * <p>
 * Internal to the accept method of TriangleVisitable or SquareVisitable
 * you will see the visit method is called on the Visitor (e.g. this class)
 *
 * @author John Dickerson
 */
public class BigShapeVisitor implements ShapeVisitor {

    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.visitor.
     *      ShapeVisitor#getName()
     */
    @Override
    public String getName() {

        return "BigShapeVisitor";
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.visitor.
     *      ShapeVisitor#visit(com.javaspeak.designpatterns.go4.behavioural.
     *          visitor.TriangleVisitable)
     */
    @Override
    public void visit( TriangleVisitable triangleVisitable ) {

        StringBuilder shapeSB = new StringBuilder();
        shapeSB.append( "    x    \n" );
        shapeSB.append( "   xxx   \n" );
        shapeSB.append( "  xxxxx  \n" );
        shapeSB.append( " xxxxxxx \n" );
        shapeSB.append( "xxxxxxxxx\n" );
        shapeSB.append( "\nTriangle\n" );

        String characterToBuild = triangleVisitable.getCharacter();

        String shape = shapeSB.toString();
        shape = shape.replaceAll( "x",  characterToBuild );

        System.out.println( shape );
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.visitor.
     *      ShapeVisitor#visit(com.javaspeak.designpatterns.go4.behavioural.
     *          visitor.SquareVisitable)
     */
    @Override
    public void visit( SquareVisitable squareVisitable ) {

        StringBuilder shapeSB = new StringBuilder();
        shapeSB.append( "xxxxxxxx\n" );
        shapeSB.append( "xxxxxxxx\n" );
        shapeSB.append( "xxxxxxxx\n" );
        shapeSB.append( "xxxxxxxx\n" );
        shapeSB.append( "xxxxxxxx\n" );
        shapeSB.append( "\n" );
        shapeSB.append( squareVisitable.getTitle() ).append( "\n" );

        System.out.println( shapeSB.toString() );
    }
}
